package com.hundsun.fcp.manager;

import android.content.SharedPreferences;

import com.hundsun.fcp.common.logger.AndroidLogger;
import com.hundsun.fcp.common.logger.Logger;
import com.hundsun.fcp.common.utils.StringUtils;
import com.hundsun.fcp.manager.SettingManager.FcpUserSetting;

public class FcpUserManager {
	private static Logger logger = new AndroidLogger();
	private static final String PREFERENCES_NAME = "fcp.setting";
	private static FcpUserManager instance;
	/** share 用户clinetno*/
    public static final String  USER_CLIENTNO = "clientno" ;
    public static final String  USER_PWD = "pwd" ;
    public static final String  USER_MOBILE = "mobile";

	public static FcpUserManager getInstance() {
		if (instance == null) {
			instance = new FcpUserManager();
		}
		return instance;
	}
	
	
	public void cleanStoredUserInfo() {
		clear(USER_CLIENTNO) ;
		clear(USER_PWD) ;
	}
	
	/**
	 * 判断用户是否登录
	 * @return
	 */
	public boolean hasLoginUser()
	{
		return !StringUtils.isEmpty(getUserClientNo()) ;
	}

	public String getUserClientNo() {
		return getValue(USER_CLIENTNO);
	}
	
	public String getUserMobile(){
		return getValue(USER_MOBILE) ;
	}

	public void storeUserInfo(String clientno, String mobile, String password) {
		put(USER_CLIENTNO, clientno) ;
		put(USER_MOBILE, mobile) ;
		put(USER_PWD, password) ;
	}
	
	public static void put(String key,String value){
		SharedPreferences.Editor editor = SettingManager.getPreferences(PREFERENCES_NAME).edit();
		editor.putString(key, value);
		editor.commit();
	}
	
	public static String getValue(String key){
		return SettingManager.getPreferences(PREFERENCES_NAME).getString(key, null) ;
	}
	
	/**
	 * 根据key 删除value
	 * @param key
	 */
	public static void clear(String key){
		SharedPreferences.Editor editor = SettingManager.getPreferences(PREFERENCES_NAME).edit() ;
		editor.remove(key) ;
		editor.commit() ;
	}
}
